package cn.shanks.springbootshirojwt.controller;

import cn.shanks.springbootshirojwt.publisher.UserLoginEvent;
import cn.shanks.springbootshirojwt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Shanks
 * @version 1.0
 * @program cn.shanks.springbootshirojwt.controller
 * @description
 * @date 2020/11/10 11:25
 */
@RestController
@RequestMapping("/user")
public class UserController implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher applicationEventPublisher;

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public String login(String username, String password) {
        applicationEventPublisher.publishEvent(new UserLoginEvent(this));
        userService.getAllUsers();
        return "12345";
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }
}
